package com.tywj.terminalapp.utils;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.tywj.terminalapp.R;

public class TaylorToast {
    public static TaylorToast mToastJoe;
    private Toast toast;

    private TaylorToast() {
    }

    public static TaylorToast getmToastJoe() {
        if (mToastJoe == null) {
            mToastJoe = new TaylorToast();
        }
        return mToastJoe;
    }

    /**
     * 显示
     */
    @SuppressLint("WrongConstant")
    public void ToastShowRight(Context context, ViewGroup root, String str) {
        TextView text = null;
        if (toast==null){
            View view = LayoutInflater.from(context).inflate(R.layout.toast_right_layout, root);
            text = view.findViewById(R.id.textToast);
            text.setText(str); // 设置显示文字
            toast = new Toast(context);
            toast.setGravity(Gravity.CENTER, 0, 0); // Toast显示的位置
            toast.setDuration(10000); // Toast显示的时间
            toast.setView(view);
        }else{
            text = toast.getView().findViewById(R.id.textToast);
            text.setText(str); // 设置显示文字
        }
        toast.show();
    }


    @SuppressLint("WrongConstant")
    public void ToastLongShow(Context context, ViewGroup root, String str) {
        TextView text = null;
        if (toast==null){
            View view = LayoutInflater.from(context).inflate(R.layout.toast_layout, root);
            text = view.findViewById(R.id.textToast);
            text.setText(str); // 设置显示文字
            toast = new Toast(context);
            toast.setDuration(10000); // Toast显示的时间
            toast.setGravity(Gravity.CENTER, 0, 0); // Toast显示的位置
            toast.setView(view);
        }else{
            text = toast.getView().findViewById(R.id.textToast);
            text.setText(str); // 设置显示文字
        }
        toast.show();
    }

    public void ToastCancel() {
        if (toast != null) {
            toast.cancel();
        }
    }
}
